<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Maps</title>
<style type="text/css">
body { margin:0; padding:0; font-size:12px; text-align:center; }
.main { margin:0px auto; width:514px; position:relative; }
.main form { height:30px; line-height:30px; overflow:hidden; }
#mapArea { width:512px; height:320px; border:1px #999 solid; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAAv20oHF8C1mcos0M9rS82nxQ0EGFgvaJ9_Sta62Xzx6a4fgMN4xRvRKlMlvUt_Ic4Om_pPr2C-ckklg"></script>
<script type="text/javascript">
var mapWidth = 512;
var mapHeight = 320;
var mapType;
var center_lat = 0;
var center_lng = 0;
var marker_lat = 0;
var marker_lng = 0;
var setZoom = 3;
var arrMapname = {'地图':'map','混合地图':'hybrid','卫星':'satellite','地形':'terrain'};

function $(id){return document.getElementById(id);}
function initMap(zoom) {
	zoom = zoom ? zoom : setZoom;
	var address = $('address').value;
	var map = new GMap2($('mapArea'));
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(address,function (point){      
				if (!point)alert(address + " 地址错误");
				else {       
					map.setCenter(point, zoom);
					map.addControl(new GScaleControl());

					map.enableDoubleClickZoom();
					map.enableScrollWheelZoom();
					map.setUIToDefault();

					var marker = new GMarker(point, {draggable: true});
					GEvent.addListener(marker, "dragend", function() {
						marker_lat = marker.getLatLng().lat(); 
						marker_lng = marker.getLatLng().lng(); 
						});
					map.addOverlay(marker);
				}
			});

	GEvent.addListener(map, "maptypechanged", function() {mapType = map.getCurrentMapType().getName();});
	GEvent.addListener(map, "moveend", function(){
		center_lat = map.getCenter().lat();
		center_lng = map.getCenter().lng();
		setZoom = map.getZoom();
	});
}
function pasteMap() {
	if (marker_lat == 0) marker_lat = center_lat;
	if (marker_lng == 0) marker_lng = center_lng;
	callback("http://maps.google.com/maps/api/staticmap?center=" + center_lat + ',' + center_lng + "&zoom=" + setZoom + "&size=" + mapWidth + 'x' + mapHeight + "&maptype=" + arrMapname[mapType] + "&markers=" + marker_lat + ',' + marker_lng + "&sensor=false");
}
function searchMap() {
	initMap(setZoom);
	return false;
}
</script>
</head>
<body onload="initMap()" onunload="GUnload()">
<div class="main">
  <div id="mapArea"></div>
  <form onsubmit="return searchMap()">
    地址：
    <input type="text" name="address" id="address" value="中国" onfocus="this.select()" />
    <input type="submit" value="搜索" />
    <input type="button" value="插入地图" onclick="pasteMap()" />
  </form>
</div>
</body>
</html>